<style lang="less" scoped>
  .page__wrapper {
    width: 100%;
    height: 100%;
  }
</style>

<template>
  <div class="page__wrapper" @keydown.enter="handleDataSearch">
    <simple-table :table-column="tableColumn" :table-data="tableData" :table-page-info="tablePageInfo" :table-data-count="tableDataTotalCount" @page-info-change="handlePageInfoChange">
      <template slot="searchSection">
        <simple-form v-model="searchModel" :form-field="searchFormField">
          <template slot="tableOperation">
            <el-button @click="handleDataSearch">{{$t('operation.search')}}</el-button>
          </template>
        </simple-form>
      </template>
      <template slot-scope="scope" slot="uploadquarter">
        {{ $getDictLabel({type: '季度', value: scope.row.uploadquarter}) }}
      </template>
      <template slot="operation" slot-scope="scope">
        <el-button v-if="actionList.indexOf('view') >= 0" circle icon="el-icon-search" :title="$t('operation.view')" @click="handleViewClick(scope.row)"></el-button>
      </template>
    </simple-table>
    <detail-dialog :show-flag.sync="isShowDetailDialog" :detail-data="rowData" :view-flag="isViewFlag" :ext-data="{sys_mid}"></detail-dialog>
  </div>
</template>
<script>
/** 混入分页信息及数据总数信息 */
import pageMixins from '@/components/base/simple-table/page-mixins'
import detailDialog from './detail'

const BASEURL = {
  list: `/web/SysAdmin/ajax.html?sys_method=GetList&sys_objName=Sys_Import_Log_Head&sys_tableName=Sys_Import_Log_Head`,
  getInitConfig: '/Web/SysAdmin/ajax.html?sys_method=GetInitConfig'
}
export default {
  name: 'log_import',
  mixins: [pageMixins],
  components: { detailDialog },
  data () {
    return {
      searchModel: {
        objName: this.$route.query.objName
      },
      rowData: {},
      /** 是否显示详情页 dialog */
      isShowDetailDialog: false,
      /** 是否为查看数据 */
      isViewFlag: false,
      actionList: [],
      /** 表格数据 */
      tableData: [],
      sys_mid: ''
    }
  },
  watch: {
    '$route.query.objName' (newObjName) {
      this.searchModel.objName = newObjName
      this.handleInitData()
    }
  },
  computed: {
    searchFormField () {
      return [
        { prop: 'uploadyear', label: this.$t('balance_factory.uploadyear'), type: 'Datepicker', component: { clearable: true, type: 'year', valueFormat: 'yyyy' } },
        { prop: 'uploadquarter', label: this.$t('balance_factory.uploadquarter'), type: 'Select', component: { clearable: true, optionList: this.$getDictList('季度') } },
        { slotName: 'tableOperation', col: { span: 12, style: { textAlign: 'right' } }, labelWidth: '0' }
      ]
    },
    tableColumn () {
      return [
        { prop: 'uploadyear', label: '年份', width: 50 },
        { prop: 'uploadquarter', label: '季度', slotName: 'uploadquarter', width: 70 },
        { prop: 'excelname', label: 'Excel名称' },
        { prop: 'uploadorganization', label: '企业名称' },
        { prop: 'createtime', label: '上传时间', width: '135px' },
        { prop: 'createby', label: '上传人', width: '130px' },

        { label: this.$t('field.operation'), slotName: 'operation', width: 55, fixed: 'right', align: 'center' }
      ]
    }
  },
  methods: {
    handleDataSearch () {
      let params = Object.assign({}, this.tablePageInfo, { sys_mid: this.sys_mid }, { sys_search: this.searchModel })

      let loadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })
      this.$axios.post(BASEURL.list, this.$_.cloneDeep(params))
        .then(resp => {
          this.tableData = resp.rows
          this.tableDataTotalCount = resp.total
        })
        .finally(() => {
          loadingFlag.close()
        })
    },
    handleInitData () {
      let configLoadingFlag = this.$loading({ fullscreen: false, target: this.$el, text: this.$t('tip.systemLoading') })
      this.$axios.post(BASEURL.getInitConfig)
        .then(resp => {
          this.actionList = resp.actionKeys.split(',')
          this.sys_mid = resp.mid

          this.handleDataSearch()
        })
        .finally(() => {
          configLoadingFlag.close()
        })
    },
    handleViewClick (row) {
      this.rowData = this.$_.cloneDeep(row)
      this.isViewFlag = true
      this.isShowDetailDialog = true
    }
  },
  mounted () {
    this.handleInitData()
  }
}
</script>
